package com.groupnections.server.database;

import java.util.Properties;

import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;

/**
 * 
 * 
 * @Architecture
 */
public class DatabaseConnection {

	public static Properties getAppengineDatabaseProperties() {

		Properties properties = new Properties();

		properties
				.setProperty("javax.jdo.PersistenceManagerFactoryClass",
						"org.datanucleus.store.appengine.jdo.DatastoreJDOPersistenceManagerFactory");

		properties.setProperty("javax.jdo.option.ConnectionURL", "appengine");

		properties.setProperty("javax.jdo.option.NontransactionalRead", "true");
		properties
				.setProperty("javax.jdo.option.NontransactionalWrite", "true");
		properties.setProperty("javax.jdo.option.RetainValues", "true");
		properties.setProperty("datanucleus.appengine.autoCreateDatastoreTxns",
				"true");

		return properties;
	}

	public static PersistenceManager connect() {

		PersistenceManagerFactory PMF = JDOHelper
				.getPersistenceManagerFactory(getAppengineDatabaseProperties());

		PersistenceManager persistenceManager = PMF.getPersistenceManager();

		return persistenceManager;
	}

}
